package com.yun.service;

import com.yun.dao.UserMapper;
import com.yun.pojo.User;
import com.yun.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class UserServiceImp implements UserService {
    SqlSession session ;
    @Override
    public User getUser(String code) {
        //获取Sqlsession
        session = MybatisUtil.getSession();
        User user = session.getMapper(UserMapper.class).getAllUser(code);
        return user;
    }

    @Override
    public int addUser(User user) {
        session = MybatisUtil.getSession();
        int i = session.getMapper(UserMapper.class).addUser(user);
        if(i>0){
            session.commit();
        }else {
            session.rollback();
        }
        return i;
    }

    @Override
    public User queryUser(String uname, String pwd) {
        session = MybatisUtil.getSession();
        User user = session.getMapper(UserMapper.class).queryUser(uname, pwd);
        return user;
    }
}
